<?php
/*
 * template name: Travel Deals
 * 
 * @author:Tham
 * Manga Travel-deals paged
 * 
 */
get_header();
$dsFristDeal = DealFlight::getFirstDEAL();

/*
 * Get $row by paged
 * 
 */
if (isset($_REQUEST['cat'])) {

    $id_cat = isset($_GET['cat']) ? ($_GET['cat']) : -1;
    $paginator = new Paginator();
    $scroll_page = 3;
    $per_page = 5; //5 records/page
    $current_page = isset($_GET['pg']) ? ($_GET['pg']) : 1;
    $paper_url = '?pg=';
    $inactive_page_tag = 'id="current_page"'; //id của thẻ span
    $totalRecord = DealFlight::countAllbyIdCat(DealFlight::DEAL, $id_cat);
    $next_page_text = '';
    $previous_page_text = '';
    $first_page_text = '';
    $last_page_text = '';

    $paginator->page_set($paper_url, $totalRecord[0]->total_design, $scroll_page, $per_page, $current_page, $inactive_page_tag, $next_page_text, $previous_page_text
            , $first_page_text, $last_page_text);

    $listAllDeals = DealFlight::getAllbyIdCat(DealFlight::DEAL, $paginator->start, $paginator->per_page, $id_cat);
} else {
    $paginator = new Paginator();
    $scroll_page = 3;
    $per_page = 4; //5 records/page
    $current_page = isset($_GET['pg']) ? ($_GET['pg']) : 1;
    $paper_url = '?pg=';
    $inactive_page_tag = 'id="current_page"'; //id của thẻ span
    $totalRecord = DealFlight::countRecords(DealFlight::DEAL);
    $next_page_text = '';
    $previous_page_text = '';
    $first_page_text = '';
    $last_page_text = '';

    $paginator->page_set($paper_url, $totalRecord[0]->total_design, $scroll_page, $per_page, $current_page, $inactive_page_tag, $next_page_text, $previous_page_text
            , $first_page_text, $last_page_text);


    $listAllDeals = DealFlight::getAll(DealFlight::DEAL, $paginator->start, $paginator->per_page);
}
?>
<div class="content">
    <div class="container">

        <div class="sli-deal">
            <div class="price-deal">€ <?php echo number_format($dsFristDeal[0]->price); ?></div>
	    <?php 
	    $aImgages = unserialize($dsFristDeal[0]->image);
	    foreach($aImgages as $img){?>
            <img src="<?php echo DEAL_URL . $img ?>"/>
	    <?php 
	    break;
	    }?>
            <div class="text-sli">
                <h1><?php echo $dsFristDeal[0]->name_deal; ?> <span>On Sale</span> </h1>
                <h4>Exclusive Deals-up to <?php echo $dsFristDeal[0]->discount ?>% Off</h4>
            </div>
        </div>


        <div class="row">

            <?php
            if ($listAllDeals <> "") {
                foreach ($listAllDeals as $rows) {
		    $aImages = unserialize($rows->image);
                    ?>
                    <div class="col-md-6">
                        <div class="box-deal">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="price-deal price-small">€<?php echo number_format($rows->price); ?></div>
				    <?php foreach($aImages as $img){?>
                                    <img src="<?php echo TIMTHUMB_URL ?>?src=<?php echo DEAL_URL . $img ?>&w=219&h=194"/>
				    <?php break;
				    }
				    ?>
                                </div>
                                <div class="col-md-6">
                                    <h4><a href="#"><?php echo $rows->name; ?></a></h4>
                                    <p>
                                        <?php
                                        $description = $rows->description;
                                        $description = explode("<!--more-->", $description);
                                        echo $description[0];

                                        //  echo Helper::SubStrText($description, 200) ;                        
                                        ?>
                                    </p>
                                    <a href="<?php echo get_site_url(); ?>/detail-deal?i=<?php echo $rows->deal_flight_id; ?>" class="btn btn-primary">Show deal</a>
                                </div>
                            </div>
                        </div><!--box-deal-->
                    </div><!--col-md-6-->

                    <?php
                }
            }
            ?>




        </div><!--row-->
        <br clear="all" />
        <div style="text-align: center;">
            <?php
            echo $paginator->previous_page . "         ";
            echo $paginator->next_page;
            ?>
        </diV>

    </div><!--container-->
</div><!--content-->
<?php get_footer(); ?>
